//
//  Status.swift
//  新浪微博
//
//  Created by seteny on 16/7/13.
//  Copyright © 2016年 seteny. All rights reserved.
//

import UIKit

class Status: NSObject {
    
    // 发布微博时间
    var created_at: String?
    // 微博id
    var id: Int64 = 0
    // 微博内容
    var text: String?
    // 来源
    var source: String?
    // 关注用户对象
    var user: User?
    // 转发数
    var reposts_count: Int = 0
    // 评论数
    var comments_count: Int = 0
    // 表态数
    var attitudes_count: Int = 0
    //转发微博对象
    var retweeted_status: Status?
    
    
    // kvc 构造函数
    init(dict: [String: AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    
    // 防止崩溃
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user" {
            guard let dict = value as? [String: AnyObject] else {
                return
            }
            // 代码执行到此,一定是我们要的字典格式
            user = User(dict: dict)
            
        } else if key == "retweeted_status" {
            
            guard let dict = value as? [String: AnyObject] else {
                return
            }
            
            //代码执行到此一定是我们想要的字典
            retweeted_status = Status(dict: dict)
        } else {
            
            super.setValue(value, forKey: key)
        }
    }
    
    
}
